package com.sunday.common.easy.excel.data;

import com.sunday.common.core.remoting.base.response.Response;
import com.sunday.common.easy.excel.dto.ListBlacklistLibraryResDTO;

import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Random;
import java.util.stream.Stream;

public class PseudoData {

    //初始轮询次数
    private static int pointer = 0;
    //最大轮询次数
    private final static int max = 4;

    public static Response<List<ListBlacklistLibraryResDTO>> getData() {
        Random random = new Random();
        return Response.ok(
                Optional.ofNullable(++pointer)
                        .filter(p -> p < max)
                        .map(p -> Stream
                                .iterate(1, n -> n < 10, n -> n + 1)
                                .map(i -> {
                                    ListBlacklistLibraryResDTO resDTO = new ListBlacklistLibraryResDTO();
                                    resDTO.setId(random.nextLong());
                                    resDTO.setName(pointer + "_" + i + "_测试名称");
                                    resDTO.setCreateTime(LocalDateTime.now());
                                    return resDTO;
                                })
                                .toList()
                        )
                        .orElseGet(() -> {
                            pointer = 0;
                            return Collections.emptyList();
                        })
        );
    }

}
